//
//  StatusOriginalView.m
//  weibo
//
//  Created by qiuming on 15/12/26.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "StatusOriginalView.h"
#import "StatusCellCommon.h"
#import <SDWebImage/UIImageView+WebCache.h>

@implementation StatusOriginalView {
    /// 头像视图
    UIImageView *_iconView;
    /// 用户昵称
    UILabel *_nameLabel;
    /// 会员等级
    UIImageView *_memberImageView;
    /// 认证图像
    UIImageView *_vipImageView;
    /// 时间标签
    UILabel *_timeLabel;
    /// 来源标签
    UILabel *_sourceLabel;
    /// 内容标签
    UILabel *_contentLabel;
}

- (void)setViewModel:(StatusViewModel *)viewModel {
    _viewModel = viewModel;
    
    [_iconView sd_setImageWithURL:viewModel.userAvatarURL];
    _nameLabel.text = viewModel.status.user.screen_name;
    _memberImageView.image = viewModel.memberImage;
    _vipImageView.image = viewModel.verifiedImage;
    _contentLabel.text = viewModel.status.text;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    // 创建控件
    _iconView = [UIImageView imageViewWithImageName:@"avatar_default_big"];
//    _iconView.cornerRadius = 17.5;
    _nameLabel = [UILabel labelWithText:@"用户昵称" textColor:[UIColor darkGrayColor] textFont:14];
    _memberImageView = [UIImageView imageViewWithImageName:@"common_icon_membership_level1"];
    _vipImageView = [UIImageView imageViewWithImageName:@"avatar_vip"];
    _timeLabel = [UILabel labelWithText:@"刚刚" textColor:[UIColor darkGrayColor] textFont:10];
    _sourceLabel = [UILabel labelWithText:@"百度" textColor:[UIColor darkGrayColor] textFont:10];
    _contentLabel = [UILabel labelWithText:@"早中瑁 于上不睛早班" textColor:[UIColor darkGrayColor] textFont:15];
    
    // 添加控件
    [self addSubview:_iconView];
    [self addSubview:_nameLabel];
    [self addSubview:_memberImageView];
    [self addSubview:_vipImageView];
    [self addSubview:_timeLabel];
    [self addSubview:_sourceLabel];
    [self addSubview:_contentLabel];
    // 自动布局
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(kStatusCellMargin);
        make.left.equalTo(self.mas_left).offset(kStatusCellMargin);
        make.size.mas_equalTo(CGSizeMake(kStatusCellIconWidth, kStatusCellIconWidth));
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_iconView.mas_top);
        make.left.equalTo(_iconView.mas_right).offset(kStatusCellMargin);
    }];
    [_memberImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLabel.mas_top);
        make.left.equalTo(_nameLabel.mas_right).offset(kStatusCellMargin);
    }];
    [_vipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_iconView.mas_right);
        make.centerY.equalTo(_iconView.mas_bottom);
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_iconView.mas_bottom);
        make.left.equalTo(_nameLabel.mas_left);
    }];
    [_sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_timeLabel.mas_top);
        make.left.equalTo(_timeLabel.mas_right).offset(kStatusCellMargin);
    }];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_iconView.mas_left);
        make.right.equalTo(self.mas_right).offset(-kStatusCellMargin);
        
        make.top.equalTo(_iconView.mas_bottom).offset(kStatusCellMargin);
    }];
    
    // 设置视图底部约束
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_contentLabel.mas_bottom).offset(kStatusCellMargin);
    }];
    
}



@end







